﻿/*
 * 
 * 类    名：PrintReport
 * 
 * 功能描述：打印报表相关公用类
 * 
 * 创 建 者：刘海洋
 * 
 * 创建日期：2009.09.09
 * 
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.IO;
using System.Collections;
using System.Data;

namespace YTBZ.PUB.Common
{
    public class PrintReport
    {
        #region  获取报表路径

        #region 报表路径 getRptPath
        public string getRptPath(string BaseFactID, string KBType)
        {
            #region 获取报表模板路径
            String rptUrl = ""; string FIELD_RPT = "";bool isAdd = false;
            string strBaseFact = "V_BASEFACTID";
            switch (KBType)
            {
                case "KB"://看板
                    FIELD_RPT = "RPT_KB";
                    break;
                case "KBCLASSER"://排序看板勾选打印，只打印看板和二维码，不打排序单
                case "KBCLASSPCER"://排序看板，只打印看板和二维码，不打排序单 按批次批量打印
                    FIELD_RPT = "RPT_CLASS";
                    break;
                case "OUTLOAD"://装车单
                    FIELD_RPT = "RPT_OTH2";
                    break;
                case "TWDHU"://拉动单HU标签
                case "TWDHUS"://(勾选打印)拉动单HU标签
                    FIELD_RPT = "RPT_KB";
                    strBaseFact = "V_BASEFACTCODE";
                    isAdd = true;
                    break;
            }
            if (!string.IsNullOrEmpty(BaseFactID) && !string.IsNullOrEmpty(FIELD_RPT))
            {
                SortedList SDListURL = new SortedList();
                SDListURL[strBaseFact] = BaseFactID;
                DataTable dtURL = new DB().proGetDT(SDListURL, "PRO_PUBGA.BASEFACTQUERY");
                if (isAdd)
                    rptUrl = dtURL.Rows.Count > 0 ? dtURL.Rows[0][FIELD_RPT].ToString() + "$" + dtURL.Rows[0]["RPT_OTH4"].ToString() : "";
                else
                    rptUrl = dtURL.Rows.Count > 0 ? dtURL.Rows[0][FIELD_RPT].ToString() : "";
            }

            if (string.IsNullOrEmpty(rptUrl))
            {
                rptUrl = GetUrl(KBType, "1");
            }
            #endregion
            return rptUrl;
        }
        #endregion

        /// <summary>
        /// 可设置A4、10*7、二等分21*14、四等分21*7
        /// </summary>
        /// <param name="KBType"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public static string GetCC(string KBType,ref string width, ref string height)
        {
            string FIELD_RPT = "";
            switch (KBType)
            {
                case "A4":
                    width = "210"; height = "279";//210*297
                    break;
                case "A5":
                    width = "210"; height = "145";//210*148
                    break;
                case "10*7"://看板、排序看板，只打印看板和二维码，不打排序单 按批次批量打印
                    width = "100"; height = "70";
                    break;
                case "21*14"://241压感纸
                    width = "210"; height = "140";
                    break;
                case "21*7"://281压感纸
                    width = "210"; height = "70";
                    break;
            }
            return FIELD_RPT;
        }
        /// <summary>
        /// 获取报表路径
        /// </summary>
        /// <param name="flwslb">法律文书类别</param>
        /// <param name="versionNumber">法律文书版本号</param>
        /// <returns></returns>
        public static string GetUrl(string flwslb, string versionNumber)
        {
            //string ReportTitle = "1";
            //if (HttpContext.Current.Application["ReportTitle"] != null)
            //{
            //    ReportTitle = HttpContext.Current.Application["ReportTitle"].ToString();
            //}
            string url = string.Empty;
            string temp = "";
            switch (flwslb)
            {
                #region 入库
                case "NEEDRECIVE"://远天供货单

                    url = ("/REPORTING/NEEDRECIVE.rdlc");
                    break;
                case "GOODINS"://勾选打印入库单
                    url = ("/REPORTING/GOODIN.rdlc");
                    break;
                case "GOODINSPACEREG"://入库储位单
                    url = ("/REPORTING/GOODINSPACEREG.rdlc");
                    break;
                case "SPACEREG"://实时储位单
                    url = ("~/REPORTING/GOODINSPACEREGCURR.rdlc");
                    break;
                #endregion

                #region 储位管理
                case "GOODMOVEFEEDBIN": //合并打印补料单
                    url = ("~/REPORTING/GOODMOVEFEEDBIN.rdlc");
                    break;
                #endregion

                #region 出库
                case "KB"://配套看板

                    url = "/REPORTING/KB01.rdlc";
                 
                    break;
                case "OUT": //出库单
                    url = ("~/REPORTING/GOODOUT_INFO.rdlc");
                    break;
                #endregion

                #region 排序
                case "KBCLASS"://排序看板勾选打印，要打排序单
                case "KBCLASSPC"://排序看板，要打排序单,按批次批量打印，
                    url = ("/REPORTING/KBCLASSLIST.rdlc");
                    break;
                case "KBCLASSER"://排序看板勾选打印，只打印看板和二维码，不打排序单
                case "KBCLASSPCER"://排序看板，只打印看板和二维码，不打排序单 按批次批量打印
                    url = "/REPORTING/KBCLASSERLIST.rdlc";
        
                    break;
                case "KDPTFLD_P":    //
                    switch (versionNumber)
                    {
                        case "1":
                            url = "KDPTFLD_P.rpt";
                            break;
                        case "2":
                            url = "KDPTFLD3050.rpt";
                            break;
                        case "3":
                            url = "KDPTFLD3050_P.rpt";
                            break;
                        default:
                            url = "KDPTFLD50100.rpt";
                            break;
                    }
                    break;
                #endregion

                #region 对位
                case "CHESTRELATION"://配套看板
                    url = ("~/REPORTING/DL/CHEST_RELATION.rdlc");
                    break;

                #endregion

                default: break;
            }
          

            return temp + "\\" + url;

        }

        #endregion

        #region  获取表名
        /// <summary>
        /// 获取表名
        /// </summary>
        /// <param name="flwslb">法律文书类别</param>
        /// <returns></returns>
        public static string TableName(string flwslb)
        {

            string tableName = "";
            switch (flwslb)
            {
                case "TXXDMB":	  //模板-铁箱箱单
                case "ZXXDMB":    //模板-纸箱箱单                
                case "ZXXDMBZX1":  //
                    tableName = "YT_S_OrderMBXX";
                    break;
                case "ZXXDMBWL1"://
                    tableName = @"YT_S_OrderMBXX A,
                                  (select distinct XX.ZXBH,XX.MBID from YT_S_OrderMBXX XX,YT_S_OrderMBTX TX
	                               where XX.MBID=TX.MBID and XX.TXBH=TX.TXBH and XX.MBID=@MBID and XX.WLBH=@WLBH and XX.deleted='0' and TX.TXType=@TXType ) B";
                    break;
                case "TXXDBZ":
                case "ZXXDBZ":    //
                    tableName = "YT_S_WLBZXX bz ";
                    break;
                case "KDPTFLD_P":    //
                    tableName = "YT_H_KDPTFLD_P";
                    break;
				case "ZXXDMBZX"://打印纸箱箱单（根据纸箱号）
				case "ZXXDMBWL": //打印纸箱箱单（根据物料号）
				case "MBXX_ZXXD":   //测（批打）打印纸箱箱单（根据铁箱清单）全部
                case "MBXX_PartZXXD":    //（批打）部分打印纸箱箱单（根据纸箱号）
                case "MBXX_PartZXXD1":    //（批打）部分打印纸箱箱单（根据勾选的纸箱号）
				case "ZXXDMBTX":	//测（批打）打印纸箱箱单（根据铁箱号）
				case "TXXDMBTX":	//（批打）打印铁箱箱单（根据铁箱号）
                case "MBXX_PartTXXD":    //（批打）部分打印铁箱箱单（根据模板信息的铁箱号）
				case "MBXX_TXXD":    //（批打）打印铁箱箱单（根据铁箱清单）全部 
                case "ZXXDMBBZSJ":    //（批打）打印翻包件、原装件（根据包装计划）全部 
                case "LZJMBBZSJ":    //（批打）打印裸装件（根据包装计划）全部 
                case "TXXDMBBZSJ":    //（批打）打印铁箱箱单（根据包装计划）全部 
                case "ZXXDMBWL_Part": //打印纸箱箱单（根据部分物料号）
                    tableName = "YT_S_OrderMBXX_TX";
                    break;
                case "MBXX_TXXD1":    //铁箱打印-铁箱清单（模板） 
                    tableName = "YT_S_OrderMBXX_TX as YT_S_OrderMBXX_TX_TX";
                    break;
                case "MBXX_TXXD2":    //铁箱打印-铁箱清单（模板） 
                    tableName = "YT_S_OrderMBXX_TX as YT_S_OrderMBXX_TX_ZX";
                    break;
                case "WLBZXX_PartZXXD":    //（批打）部分打印纸箱箱单（根据实际包装清单的纸箱号）
                case "WLBZXX_PartTXXD":    //（批打）部分打印铁箱箱单（根据实际包装清单的铁箱号）
                case "WLBZXX_OneTXXD":      //（单打）打印铁箱箱单（根据实际包装清单的铁箱号）
                    tableName = "YT_S_WLBZXX as YT_S_OrderMBXX_TX";
                    break;
                default:
                    break;
            }
            return tableName;
        }
        #endregion

        #region  获取dateTime的大写日期
        /// <summary>
        /// 获取dateTime的大写日期
        /// </summary>
        /// <param name="dateTime">日期</param>
        /// <returns>返回dateTime的大写日期</returns>
        public static string GetCapDate(DateTime dateTime)
        {

            string[] chinese = { "○", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
            string capYear = "", capMonth = "", capDay = "";
            string m_year, m_month, m_day;
            m_year = dateTime.Year.ToString();
            m_month = dateTime.Month.ToString();
            m_day = dateTime.Day.ToString();
            //取年份

            for (int i = 0; i < m_year.Length; i++)
            {
                capYear += chinese[Convert.ToInt32(m_year.Substring(i, 1))];
            }
            //取月
            if (m_month.Length == 2)
            {
                if (m_month.Substring(0, 1) == "1")
                {
                    capMonth = "十" + chinese[Convert.ToInt32(m_month.Substring(1, 1))];
                }
                else
                {
                    capMonth = chinese[Convert.ToInt32(m_month.Substring(0, 1))] + "十" + chinese[Convert.ToInt32(m_month.Substring(1, 1))];
                }
            }
            else
            {
                capMonth = chinese[Convert.ToInt32(Convert.ToInt32(m_month))];
            }
            if (capMonth.Length > 0)   //取掉未尾的"0";
            {
                capMonth = capMonth.TrimEnd(new char[] { '○' });
            }
            //取日
            if (m_day.Length == 2)
            {
                if (m_day.Substring(0, 1) == "1")
                {
                    capDay = "十" + chinese[Convert.ToInt32(m_day.Substring(1, 1))];
                }
                else
                {
                    capDay = chinese[Convert.ToInt32(m_day.Substring(0, 1))] + "十" + chinese[Convert.ToInt32(m_day.Substring(1, 1))];
                }
            }
            else
            {
                capDay = chinese[Convert.ToInt32(Convert.ToInt32(m_day))];
            }
            if (capDay.Length > 0)
            {
                capDay = capDay.TrimEnd(new char[] { '○' });
            }
            return capYear + "年" + capMonth + "月" + capDay + "日";

        }
        #endregion

        public static string windowopen(string FlwsID, string flwslb, string version)
        {
            string url = "PrintPreviewPage.aspx?flwsID={0}&flwslb={1}&Version={2}";
            url = string.Format(url, FlwsID, flwslb, version);
            return url;
            //MessageBox.PoP_Notice_Msg(url, "", 6);
            //HttpContext.Current.Response.Write("<script language=javascript>\n");
            //HttpContext.Current.Response.Write("window.opener.location.reload();");
            //HttpContext.Current.Response.Write(" window.opener.window.open('" + url + "','', 'top=0,left=0,width=1014,height=700,scrollbars=yes,resizable=yes,menubar=yes');\n");
            //HttpContext.Current.Response.Write("window.close();\n");
            //HttpContext.Current.Response.Write("</script>");
        }
    }
}
